//package com.example.jinzproduct.oss.impl;
//
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.example.jinzproduct.config.IFastConfig;
//import com.example.jinzproduct.dao.FileDao;
//import com.example.jinzproduct.entity.FileDO;
//import com.example.jinzproduct.oss.DictService;
//import com.example.jinzproduct.oss.FileService;
//import com.example.jinzproduct.oss.UploadServer;
//import com.example.jinzproduct.util.DateUtils;
//import com.example.jinzproduct.util.FileType;
//import com.example.jinzproduct.util.FileUtil;
//import lombok.AllArgsConstructor;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.web.multipart.MultipartFile;
//
//import java.io.*;
//import java.util.Date;
//
///**
// * <pre>
// * </pre>
// *
// * <small> 2018年3月23日 | Aron</small>
// */
//@Service
//@AllArgsConstructor
//public class FileServiceImpl extends ServiceImpl<FileDao, FileDO> implements FileService {
//
//    @Autowired
//    private IFastConfig huahaoConfig;
//    private UploadServer uploader;
//    @Autowired
//    private DictService dictService;
//
//
//    @Override
//    public String upload(byte[] uploadBytes, String fileName) {
//        //String url = uploader.upload(uploadBytes, FileNameUtils.getFileName(fileName, ifastConfig));
//        String url = uploader.upload(uploadBytes, fileName);
//        url = url.replace("\\","/");
//        FileDO sysFile = new FileDO(FileType.fileType(fileName), url, new Date());
//        super.save(sysFile);
//        return url;
//    }
//
////    @Override
////    public String upload(byte[] uploadBytes, String fileName) {
////        fileName = fileName.substring(0, fileName.indexOf(".")) + "-" + System.currentTimeMillis() + fileName.substring(fileName.indexOf("."));
////        fileName = huahaoConfig.getProjectName() + "/" + DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN_8)
////                + "/" + fileName;
////        String url = uploader.upload(uploadBytes, fileName);
////        FileDO sysFile = new FileDO(FileType.fileType(fileName), url, new Date());
////        super.insert(sysFile);
////        return url;
////    }
//
//    public String upload(MultipartFile file) {
//        String fileName = file.getOriginalFilename();
//        fileName = fileName.substring(0, fileName.indexOf(".")) + "-" + System.currentTimeMillis() + fileName.substring(fileName.indexOf("."));
//        String fileName_suffix = "open/" + huahaoConfig.getProjectName() + "/" + DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN_8) + "/";
//        String local_path = "C:/file/";
//        String project_url = "http://114.115.217.149:8899/";
//        if (StringUtils.isBlank(local_path)){
//            //默认值
//            local_path = "C:/file/";
//        }
//        if (StringUtils.isBlank(project_url)){
//            //默认值
//            project_url = "http://localhost:8088/";
//        }
//        String filePath = local_path + fileName_suffix;
//        FileUtil.judeDirExists(new File(filePath));
//
//        String prefix = project_url + fileName_suffix;
//        String url = prefix + fileName;
//        try {
//            FileUtil.uploadFile(file.getBytes(),filePath,fileName);
//            FileDO sysFile = new FileDO(FileType.fileType(fileName), url, new Date());
//            super.save(sysFile);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return url;
//    }
//
//
//    private byte[] getBytes(File file) {
//        byte[] buffer = null;
//        try {
//            FileInputStream fis = new FileInputStream(file);
//            ByteArrayOutputStream bos = new ByteArrayOutputStream(1000);
//            byte[] b = new byte[1000];
//            int n;
//            while ((n = fis.read(b)) != -1) {
//                bos.write(b, 0, n);
//            }
//            fis.close();
//            bos.close();
//            buffer = bos.toByteArray();
//        } catch (FileNotFoundException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return buffer;
//    }
//}
